#include "gwbase/base/test_harness.h"
#include "gwbase/base/path.h"

using namespace dicom;

class PathTest { };

TEST(PathTest, Join) {
  EXPECT_Eq(path::Join("a", "b"), "a/b");
  EXPECT_Eq(path::Join("", "b"), "b");
  EXPECT_Eq(path::Join("a", ""), "a");
  EXPECT_Eq(path::Join("a/", "b"), "a/b");
  EXPECT_Eq(path::Join("a", "/b"), "a/b");
  EXPECT_Eq(path::Join("a/", "/b"), "a//b");
}

TEST(PathTest, Basename) {
  EXPECT_Eq(path::Basename("a/b"), "b");
  EXPECT_Eq(path::Basename("/b"), "b");
  EXPECT_Eq(path::Basename("a/b.txt"), "b.txt");
  EXPECT_Eq(path::Basename("a//b.txt"), "b.txt");
  EXPECT_Eq(path::Basename("b.txt"), "b.txt");
}

TEST(PathTest, Extension) {
  EXPECT_Eq(path::Extension("a/b"), "");
  EXPECT_Eq(path::Extension("/b"), "");
  EXPECT_Eq(path::Extension("a/b.txt"), "txt");
  EXPECT_Eq(path::Extension("a//b.txt"), "txt");
  EXPECT_Eq(path::Extension("b.txt"), "txt");
  EXPECT_Eq(path::Extension("."), "");
}

TEST(PathTest, Parent) {
  EXPECT_Eq(path::Parent("a/b"), "a");
  EXPECT_Eq(path::Parent("/b"), "/");
  EXPECT_Eq(path::Parent("a/b.txt"), "a");
  EXPECT_Eq(path::Parent("a//b.txt"), "a/");
  EXPECT_Eq(path::Parent("b.txt"), "");
  EXPECT_Eq(path::Parent("."), "");
}

int main() {
  RunAllTests();
  return 0;
}
